﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
using System.Data.SqlClient;


namespace Takenlijst
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            getTaken();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form f2 = new Form2();
            f2.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form f3 = new Form3();
            f3.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            getTaken();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Form f5 = new Form5();
            f5.Show();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Form f4 = new Form4();
            f4.Show();
        }

        public void getTaken()
        {
            try
            {
                int projectID = 1;
                MySqlConnection grabConnection = new MySqlConnection("Server=instance8003.db.xeround.com;Port=6006;Database=GrabCollab;Uid=cookicom0;Pwd=pizzahut91;");
                MySqlCommand takenGet = new MySqlCommand("SELECT TaakID, Taak, Status FROM taken WHERE ProjectID='"+projectID+"' ORDER BY TaakID ASC", grabConnection);
               
                //takenGet.Parameters.Add(new MySqlParameter("projectID", projectID));
                grabConnection.Open();
                
                MySqlDataReader reader = takenGet.ExecuteReader();
                
                if (reader.Read() != false)
                {
                    if (reader.IsDBNull(0) == true)
                    {
                        grabConnection.Close();
                        reader.Dispose();
                        takenGet.Dispose();
                    }
                    else
                    {
                        listView1.Items.Clear();

                        while (reader.Read())
                        {
                            ListViewItem item = new ListViewItem(reader["Taak"].ToString());
                            item.SubItems.Add(reader["TaakID"].ToString()); // hier moet naam komen
                            item.SubItems.Add(reader["Status"].ToString());

                            listView1.Items.Add(item);
                        }

                        reader.Close();
                    }

                    grabConnection.Close();
                    reader.Dispose();
                    takenGet.Dispose();
                }
            }

            catch (MySqlException)
            {
                MessageBox.Show("Sql error detected!");
            }
        }



    }
}